<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TCP vs UDP：深入理解网络协议的核心差异</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: -10px;
            width: 60px;
            height: 4px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .comparison-card {
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.9);
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                TCP vs UDP
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                深入理解网络协议的核心差异
            </p>
            <div class="flex justify-center space-x-8 text-lg">
                <div class="flex items-center">
                    <i class="fas fa-shield-alt mr-2"></i>
                    <span>可靠传输</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-bolt mr-2"></i>
                    <span>高速传输</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-network-wired mr-2"></i>
                    <span>网络基石</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto bg-white rounded-2xl shadow-xl p-10 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>现代网络通信中，TCP 和 UDP 是两个最重要的传输层协议。<strong class="text-purple-600">TCP（传输控制协议）</strong>是一个面向连接、可靠的协议，适合需要确保数据准确性和顺序的应用，但其额外的控制机制可能会影响速度。<strong class="text-purple-600">UDP（用户数据报协议）</strong>是一个无连接、不可靠的协议，适合对速度要求高且可以容忍丢包的应用，如实时通讯和流媒体服务。
            </p>
        </div>
    </section>

    <!-- Visual Comparison -->
    <section class="py-16 px-6 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 text-gradient">协议对比可视化</h2>
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="mermaid">
                    graph TD
                        A[网络通信协议] --> B[TCP 传输控制协议]
                        A --> C[UDP 用户数据报协议]
                        
                        B --> D[面向连接]
                        B --> E[可靠传输]
                        B --> F[有序传输]
                        B --> G[流量控制]
                        
                        C --> H[无连接]
                        C --> I[不可靠传输]
                        C --> J[无序传输]
                        C --> K[高速传输]
                        
                        D --> L[三次握手建立连接]
                        E --> M[确认重传机制]
                        F --> N[序列号保证顺序]
                        G --> O[拥塞控制算法]
                        
                        H --> P[直接发送数据]
                        I --> Q[无确认机制]
                        J --> R[数据包独立传输]
                        K --> S[低延迟传输]
                        
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style B fill:#764ba2,stroke:#fff,color:#fff
                        style C fill:#764ba2,stroke:#fff,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- Main Comparison Content -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <!-- 连接性 -->
            <div class="mb-16 animate-fadeInUp">
                <h3 class="text-3xl font-bold mb-8 relative inline-block section-title">
                    <i class="fas fa-link mr-3 feature-icon"></i>连接性
                </h3>
                <div class="grid md:grid-cols-2 gap-8 mt-12">
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">TCP 传输控制协议</h4>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <i class="fas fa-handshake text-purple-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">连接导向</p>
                                    <p class="text-gray-600">在数据传输之前，TCP 必须先建立连接。通过"三次握手"过程建立连接，并在数据传输结束后，通过"四次挥手"来关闭连接。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-check-circle text-green-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">特点</p>
                                    <p class="text-gray-600">这种连接确保了数据的可靠性和顺序性。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">UDP 用户数据报协议</h4>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <i class="fas fa-paper-plane text-purple-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">无连接</p>
                                    <p class="text-gray-600">UDP 是一个无连接的协议，不需要在传输数据之前建立连接，也没有关闭连接的过程。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-rocket text-blue-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">特点</p>
                                    <p class="text-gray-600">这种特性使得 UDP 数据传输更加快速，但不保证数据的可靠性和顺序性。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 可靠性 -->
            <div class="mb-16 animate-fadeInUp">
                <h3 class="text-3xl font-bold mb-8 relative inline-block section-title">
                    <i class="fas fa-shield-alt mr-3 feature-icon"></i>可靠性
                </h3>
                <div class="grid md:grid-cols-2 gap-8 mt-12">
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">TCP</h4>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <i class="fas fa-lock text-purple-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">可靠传输</p>
                                    <p class="text-gray-600">TCP 提供数据的可靠传输，通过数据包确认（ACK）、重传机制、流量控制和拥塞控制等技术，确保数据按顺序、完整地到达目标。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-search text-green-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">错误检测</p>
                                    <p class="text-gray-600">TCP 使用校验和检测数据传输中的错误，并自动重传丢失或损坏的数据包。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">UDP</h4>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <i class="fas fa-unlock text-purple-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">不保证可靠性</p>
                                    <p class="text-gray-600">UDP 不提供数据的可靠性保障。数据包可能丢失、重复或到达顺序不对。</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <i class="fas fa-times-circle text-red-600 mt-1 mr-3"></i>
                                <div>
                                    <p class="font-semibold text-gray-800">无重传机制</p>
                                    <p class="text-gray-600">UDP 不会自动重传丢失的数据包，也不提供流量控制和拥塞控制机制。</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 数据传输速度 -->
            <div class="mb-16 animate-fadeInUp">
                <h3 class="text-3xl font-bold mb-8 relative inline-block section-title">
                    <i class="fas fa-tachometer-alt mr-3 feature-icon"></i>数据传输速度
                </h3>
                <div class="grid md:grid-cols-2 gap-8 mt-12">
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">TCP</h4>
                        <div class="flex items-start">
                            <i class="fas fa-hourglass-half text-orange-600 mt-1 mr-3"></i>
                            <div>
                                <p class="font-semibold text-gray-800">较慢</p>
                                <p class="text-gray-600">由于 TCP 的连接建立、确认应答、流量控制和拥塞控制等机制，会增加一些开销，导致数据传输速度相对较慢。</p>
                            </div>
                        </div>
                    </div>
                    <div class="comparison-card rounded-xl p-8 card-hover">
                        <h4 class="text-2xl font-bold mb-4 text-purple-700">UDP</h4>
                        <div class="flex items-